package com.detection.dahua.service.impl;

import com.detection.dahua.model.brm.device.DevicePageResponse;
import java.util.ArrayList;
import java.util.List;

public class DevicePageResponseMockData {

    public static DevicePageResponse createMockDevicePageResponse() {
        DevicePageResponse response = new DevicePageResponse();
        response.setCode("0");
        response.setData(createMockPageVO());
        return response;
    }

    private static DevicePageResponse.PageVO createMockPageVO() {
        DevicePageResponse.PageVO pageVO = new DevicePageResponse.PageVO();
        pageVO.setCurrentPage(1);
        pageVO.setTotalPage(5);
        pageVO.setPageSize(10);
        pageVO.setTotalRows(45);
        pageVO.setPageData(createMockDeviceInfoList());
        return pageVO;
    }

    private static List<DevicePageResponse.PageVO.DeviceInfoVO> createMockDeviceInfoList() {
        List<DevicePageResponse.PageVO.DeviceInfoVO> deviceInfoList = new ArrayList<>();

        // 创建第一个设备
        DevicePageResponse.PageVO.DeviceInfoVO device1 = new DevicePageResponse.PageVO.DeviceInfoVO();
        device1.setDeviceCode("DEV001");
        device1.setDeviceName("网络摄像头001");
        device1.setDeviceSn("SN1234567890");
        device1.setDeviceCategory(1);
        device1.setDeviceType(101);
        device1.setDeviceManufacturer("大华");
        device1.setDeviceIp("192.168.1.101");
        device1.setDevicePort(80);
        device1.setOwnerCode("ORG001");
        device1.setIsOnline(1);
        device1.setOfflineReason("");
        device1.setSubSystem("VIDEO");
        device1.setDevExt(new Object()); // 实际应用中可能是具体的扩展属性对象
        device1.setGpsX("120.123456");
        device1.setGpsY("30.123456");
        device1.setUnits(createMockUnitList(2)); // 该设备包含2个单元

        deviceInfoList.add(device1);

        // 创建第二个设备
        DevicePageResponse.PageVO.DeviceInfoVO device2 = new DevicePageResponse.PageVO.DeviceInfoVO();
        device2.setDeviceCode("DEV002");
        device2.setDeviceName("网络摄像头002");
        device2.setDeviceSn("SN0987654321");
        device2.setDeviceCategory(1);
        device2.setDeviceType(101);
        device2.setDeviceManufacturer("海康");
        device2.setDeviceIp("192.168.1.102");
        device2.setDevicePort(80);
        device2.setOwnerCode("ORG001");
        device2.setIsOnline(0);
        device2.setOfflineReason("网络断开");
        device2.setSubSystem("VIDEO");
        device2.setDevExt(new Object());
        device2.setGpsX("120.654321");
        device2.setGpsY("30.654321");
        device2.setUnits(createMockUnitList(1)); // 该设备包含1个单元

        deviceInfoList.add(device2);

        return deviceInfoList;
    }

    private static List<DevicePageResponse.PageVO.DeviceInfoVO.UnitVO> createMockUnitList(int count) {
        List<DevicePageResponse.PageVO.DeviceInfoVO.UnitVO> unitList = new ArrayList<>();

        for (int i = 1; i <= count; i++) {
            DevicePageResponse.PageVO.DeviceInfoVO.UnitVO unit = new DevicePageResponse.PageVO.DeviceInfoVO.UnitVO();
            unit.setUnitType(1);
            unit.setUnitSeq(i);
            unit.setSort(i * 10);
            unit.setMemo("单元描述" + i);
            unit.setCapability("CAPABILITY_" + i);
            unit.setUnitExt(new Object());
            unit.setChannels(createMockChannelList(3)); // 每个单元包含3个通道

            unitList.add(unit);
        }

        return unitList;
    }

    private static List<DevicePageResponse.PageVO.DeviceInfoVO.UnitVO.ChannelVO> createMockChannelList(int count) {
        List<DevicePageResponse.PageVO.DeviceInfoVO.UnitVO.ChannelVO> channelList = new ArrayList<>();

        for (int i = 1; i <= count; i++) {
            DevicePageResponse.PageVO.DeviceInfoVO.UnitVO.ChannelVO channel = new DevicePageResponse.PageVO.DeviceInfoVO.UnitVO.ChannelVO();
            channel.setChannelCode("CHN" + String.format("%03d", i));
            channel.setChannelName("通道" + i);
            channel.setChannelSeq(i);
            channel.setChannelSn("CHSN" + String.format("%03d", i));
            channel.setChannelType("IPC");
            channel.setCapability("CHANNEL_CAPABILITY_" + i);
            channel.setAccess(1);
            channel.setGpsX("120.123" + i);
            channel.setGpsY("30.456" + i);
            channel.setGpsZ("0");
            channel.setMemo("通道描述" + i);
            channel.setStat(1);
            channel.setChExt(new Object());
            channelList.add(channel);
        }

        return channelList;
    }

    // 使用示例
    public static void main(String[] args) {
        DevicePageResponse mockData = createMockDevicePageResponse();

        // 打印部分数据验证
        System.out.println("Response Code: " + mockData.getCode());
        System.out.println("Current Page: " + mockData.getData().getCurrentPage());
        System.out.println("Total Pages: " + mockData.getData().getTotalPage());
        System.out.println("Page Size: " + mockData.getData().getPageSize());
        System.out.println("Total Rows: " + mockData.getData().getTotalRows());

        // 打印第一个设备信息
        DevicePageResponse.PageVO.DeviceInfoVO firstDevice = mockData.getData().getPageData().get(0);
        System.out.println("First Device Name: " + firstDevice.getDeviceName());
        System.out.println("First Device IP: " + firstDevice.getDeviceIp());
        System.out.println("Number of Units in First Device: " + firstDevice.getUnits().size());

        // 打印第一个单元的第一个通道信息
        DevicePageResponse.PageVO.DeviceInfoVO.UnitVO firstUnit = firstDevice.getUnits().get(0);
        DevicePageResponse.PageVO.DeviceInfoVO.UnitVO.ChannelVO firstChannel = firstUnit.getChannels().get(0);
        System.out.println("First Channel Name: " + firstChannel.getChannelName());
        System.out.println("First Channel Code: " + firstChannel.getChannelCode());
    }
}
